package com.luxuewen.sxa.utils.response;

import com.luxuewen.sxa.common.enums.ResponseEnum;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * @author wen
 */
@Data
public class ApiResponse<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    private Integer code;

    private String message;

    private T data;

    public ApiResponse(Integer code,String message){
        this.code = code;
        this.message = message;
    }

    public ApiResponse(Integer code, String message, T data){
        this(code,message);
        this.data = data;
    }

    public static <T> ApiResponse<T> success(){
        return new ApiResponse<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage());
    }

    public static <T> ApiResponse<T> success(T data){
        return new ApiResponse<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(),data);
    }

    public static <T> ApiResponse<T> fail(){
        return new ApiResponse<>(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMessage());
    }
    public static <T> ApiResponse<T> fail(String message){
        return new ApiResponse<>(ResponseEnum.FAILURE.getCode(), message);
    }

    public static <T> ApiResponse<T> fail(Integer code, String message){
        return new ApiResponse<>(code, message);
    }

    public static <T> ApiResponse<T> error(){
        return new ApiResponse<>(ResponseEnum.ERROR.getCode(), ResponseEnum.ERROR.getMessage());
    }

    public static <T> ApiResponse<T> error(Integer code, String message){
        return new ApiResponse<>(code, message);
    }
}
